<?php

namespace App\Service;

use App\Models\Area as Areas;
use tpns;
use Illuminate\Http\Request;
class PushMessage
{

    /**
     * @param Request $request
     * @throws \Exception
     * android单设备推送
     */
    public static function androidSingleEquipmentPush($data)
    {
        $android = new tpns\AndroidMessage();
//        $android->n_ch_id = "";
//        $ios = new tpns\iOSMessage;
//        $ios->custom = "{\"key\":\"value\"}";
        $req = tpns\NewRequest(
            tpns\WithAudienceType(tpns\AUDIENCE_TOKEN),
            tpns\WithMessageType(tpns\MESSAGE_NOTIFY),
            tpns\WithTitle($data['title']),
            tpns\WithContent($data["content"]),
            tpns\WithAndroidMessage($android),
//            tpns\WithIOSMessage($ios),
            tpns\WithTokenList(array($data['token'])),
            tpns\WithEnvironment(tpns\ENVIRONMENT_PROD)
        );
        //@parameter: accessId=123456, secretKey="abcdef", host="api.tpns.tencent.com"
        $stub = new tpns\Stub(config("omnipay.pushAndroid.AccessID"), config("omnipay.pushAndroid.SecretKey"),  tpns\SHANGHAI);
        $result = $stub->Push($req);
       return $result;
    }

    /**
     * @param Request $request
     * @throws \Exception
     * android单设备推送
     */
    public static function iosSingleEquipmentPush($data)
    {
//        $android = new tpns\AndroidMessage;
//        $android->n_ch_id = $data['chid'];
        $ios = new tpns\iOSMessage;
//        $dt = array("key"=>$data['chid']);
//        $ios->custom = json_encode($dt);//"{\"key\":\"value\"}";
        $req = tpns\NewRequest(
            tpns\WithAudienceType(tpns\AUDIENCE_TOKEN),
            tpns\WithMessageType(tpns\MESSAGE_NOTIFY),
            tpns\WithTitle($data['title']),
            tpns\WithContent($data["content"]),
//            tpns\WithAndroidMessage($android),
            tpns\WithIOSMessage($ios),
            tpns\WithTokenList(array($data['token'])),
            tpns\WithEnvironment(tpns\ENVIRONMENT_PROD)
        );
        //@parameter: accessId=123456, secretKey="abcdef", host="api.tpns.tencent.com"
        $stub = new tpns\Stub(config("omnipay.pushAndroid.AccessID"), config("omnipay.pushAndroid.SecretKey"), tpns\SHANGHAI);
        $result = $stub->Push($req);
       return $result;
    }




}
